﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using DCSLibrary;
using Utils.DatabaseUtils;
using Utils.DC.Web.UI;

public partial class Admin_Module_Control_quan_tri_bai_viet_don : System.Web.UI.UserControl
{
    private string newsType;
    public string NewsType
    {
        get { return newsType; }
        set { newsType = value; }
    }

    private string lang;
    public string Lang
    {
        get { return lang; }
        set { lang = value; }
    }
        
    FunctionPageUI objFunction = new FunctionPageUI();
    DataSet dsCategoryPage;

    protected void Page_Load(object sender, EventArgs e)
    {
        dsCategoryPage = objFunction.GetByFunctionType(newsType);

        if (!IsPostBack)
        {
            LoadEditData();
        }
    }


    protected void btnCreate_Click(object sender, EventArgs e)
    {
        //bien page-alias
        string alias = Utils.Format.ConvertToNoSign(txtFunctionPageName.Text.Trim());

        try
        {
            int result = objFunction.Update(Convert.ToInt32(dsCategoryPage.Tables[0].Rows[0]["FunctionPageID"]), txtFunctionPageName.Text, alias, txtFunctionPageTitle.Text, txtFunctionPageImage.Text, "",
                txtFunctionPageDescription.Content, txtMetaKeyword.Text, txtMetaDescription.Text, true, false, 0, "VN", false, newsType, false, 0, "", "/" + alias + ".aspx");

            if (result > 0)
            {
                //Response.Write(messageBox.Alert(MessageBox.MESSAGE_ADD_SUCCESSFULLY));
                lblMessage.Text = MessageBox.MESSAGE_UPDATE_SUCCESSFULLY;
                //BindFunctionPage();
                ReInsertData();
            }
            else
            {
                //Response.Write(messageBox.Alert(MessageBox.MESSAGE_ADD_NOT_SUCCESSFULLY));
                lblMessage.Text = MessageBox.MESSAGE_UPDATE_NOT_SUCCESSFULLY;
            }
        }
        catch (Exception ex)
        {
            //Response.Write(messageBox.Alert(MessageBox.MESSAGE_DUPLICATE_DATA));
            lblMessage.Text = MessageBox.MESSAGE_CONFILCT_DATA;
        }
    }

    protected void btnReset_Click(object sender, EventArgs e)
    {
        ReInsertData();
    }

    #region Cac ham tuong tac du lieu

    private void LoadEditData()
    {
        try
        {
            if (TableLib.HasData(dsCategoryPage))
            {
                DataRow row = dsCategoryPage.Tables[0].Rows[0];
                txtFunctionPageDescription.Content = row["FunctionPageDescription"].ToString();
                txtFunctionPageImage.Text = row["FunctionPageImage"].ToString();
                txtFunctionPageName.Text = row["FunctionPageName"].ToString();
                txtFunctionPageTitle.Text = row["FunctionPageTitle"].ToString();
                txtMetaDescription.Text = row["MetaDescription"].ToString();
                txtMetaKeyword.Text = row["MetaKeyword"].ToString();
            }
        }
        catch (Exception e)
        {
        }
    }

    private void ReInsertData()
    {
        txtFunctionPageDescription.Content = "";
        txtFunctionPageImage.Text = "";
        txtFunctionPageName.Text = "";
        txtFunctionPageTitle.Text = "";
        txtMetaDescription.Text = "";
        txtMetaKeyword.Text = "";
    }

    #endregion
}
